//
//  RequestManager.m
//  SheMeasured
//
//  Created by ddkj on 2019/4/3.
//  Copyright © 2019 xmddkj. All rights reserved.
//

#import "RequestManager.h"
#import <AFNetworking.h>

typedef NS_ENUM(NSUInteger, RequestMethod) {
    RequestMethodGet,
    RequestMethodPost,
    RequestMethodDelete,
    RequestMethodPush,
};

@implementation RequestManager

+ (RequestManager *)shared {
    static RequestManager *single = nil;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        single = [[RequestManager alloc] init];
    });
    
    return single;
}

- (AFHTTPSessionManager *)getDefaultManage {
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.requestSerializer.timeoutInterval = 20;
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    return manager;
}

- (void)getRequestWithUrl:(NSString *)url params:(NSDictionary *)params completion:(RequestCompletion)completion {
    AFHTTPSessionManager *manager = [self getDefaultManage];
    
    [manager GET:url parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}

- (void)postRequestWithUrl:(NSString *)url params:(NSDictionary *)params completion:(RequestCompletion)completion {
    AFHTTPSessionManager *manager = [self getDefaultManage];
    [manager POST:url parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}

@end
